Logistic Regression
Logistic regression for high income countries
grp = income_grp[1]
dat2 <- get_data(dat, grp)
fit <- nls(IT.CEL.SETS.P2 ~ SSlogis(year, Asym, xmid, scal), data=dat2)
smdls[[grp]] <- fit
summary(fit)
##
## Formula: IT.CEL.SETS.P2 ~ SSlogis(year, Asym, xmid, scal)
##
## Parameters:
## Estimate Std. Error t value Pr(>|t|)
## Asym 122.0446 1.6540 73.79 <2e-16 ***
## xmid 2004.1719 0.1856 10795.97 <2e-16 ***
## scal 3.0817 0.1522 20.25 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 33.44 on 2268 degrees of freedom
##
## Number of iterations to convergence: 2
## Achieved convergence tolerance: 1.29e-06
R2nls(fit)
## $PseudoR2
## [1] 0.6725223
##
## $R2
## [1] 0.6598708
pyear <- seq(min(dat2$year), 2030, 1)
plot(dat2, xlim = c(min(pyear), max(pyear)), ylim = c(0,140),
pch=16, col="blue", main = grp, xaxt='n',yaxt='n', cex = 0.5)
axis(1, at = seq(min(pyear), max(pyear), 1), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
axis(2, at = seq(0, 140, 10), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
matlines(pyear, predict(fit, newdata=list(year=pyear), interval="confidence"), lwd=1.25)

Logistic regression for upper middle income countries
grp = income_grp[4]
dat2 <- get_data(dat, grp)
fit <- nls(IT.CEL.SETS.P2 ~ SSlogis(year, Asym, xmid, scal), data=dat2)
smdls[[grp]] <- fit
summary(fit)
##
## Formula: IT.CEL.SETS.P2 ~ SSlogis(year, Asym, xmid, scal)
##
## Parameters:
## Estimate Std. Error t value Pr(>|t|)
## Asym 103.8021 1.4187 73.17 <2e-16 ***
## xmid 2006.1631 0.1577 12725.07 <2e-16 ***
## scal 2.3597 0.1312 17.99 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 25.01 on 1649 degrees of freedom
##
## Number of iterations to convergence: 2
## Achieved convergence tolerance: 2.834e-06
R2nls(fit)
## $PseudoR2
## [1] 0.7461331
##
## $R2
## [1] 0.7557133
pyear <- seq(min(dat2$year), 2030, 1)
plot(dat2, xlim = c(min(pyear), max(pyear)), ylim = c(0,140),
pch=16, col="blue", main = grp, xaxt='n',yaxt='n', cex = 0.5)
axis(1, at = seq(min(pyear), max(pyear), 1), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
axis(2, at = seq(0, 140, 10), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
matlines(pyear, predict(fit, newdata=list(year=pyear), interval="confidence"), lwd=1.25)

Logistic regression for lower middle income countries
grp = income_grp[3]
dat2 <- get_data(dat, grp)
fit <- nls(IT.CEL.SETS.P2 ~ SSlogis(year, Asym, xmid, scal), data=dat2)
smdls[[grp]] <- fit
summary(fit)
##
## Formula: IT.CEL.SETS.P2 ~ SSlogis(year, Asym, xmid, scal)
##
## Parameters:
## Estimate Std. Error t value Pr(>|t|)
## Asym 105.3133 1.9229 54.77 <2e-16 ***
## xmid 2007.1758 0.2110 9513.78 <2e-16 ***
## scal 2.8334 0.1686 16.80 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 26.78 on 1577 degrees of freedom
##
## Number of iterations to convergence: 2
## Achieved convergence tolerance: 1.376e-06
R2nls(fit)
## $PseudoR2
## [1] 0.7025343
##
## $R2
## [1] 0.71155
pyear <- seq(min(dat2$year), 2030, 1)
plot(dat2, xlim = c(min(pyear), max(pyear)), ylim = c(0,140),
pch=16, col="blue", main = grp, xaxt='n',yaxt='n', cex = 0.5)
axis(1, at = seq(min(pyear), max(pyear), 1), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
axis(2, at = seq(0, 140, 10), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
matlines(pyear, predict(fit, newdata=list(year=pyear), interval="confidence"), lwd=1.25)

Logistic regression for low income countries
grp = income_grp[2]
dat2 <- get_data(dat, grp)
fit <- nls(IT.CEL.SETS.P2 ~ SSlogis(year, Asym, xmid, scal), data=dat2)
smdls[[grp]] <- fit
summary(fit)
##
## Formula: IT.CEL.SETS.P2 ~ SSlogis(year, Asym, xmid, scal)
##
## Parameters:
## Estimate Std. Error t value Pr(>|t|)
## Asym 99.3575 3.6853 26.960 <2e-16 ***
## xmid 2007.5478 0.4337 4628.602 <2e-16 ***
## scal 3.2046 0.3272 9.795 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 30.35 on 788 degrees of freedom
##
## Number of iterations to convergence: 1
## Achieved convergence tolerance: 5.193e-06
R2nls(fit)
## $PseudoR2
## [1] 0.6035689
##
## $R2
## [1] 0.5966871
pyear <- seq(min(dat2$year), 2030, 1)
plot(dat2, xlim = c(min(pyear), max(pyear)), ylim = c(0,140),
pch=16, col="blue", main = grp, xaxt='n',yaxt='n', cex = 0.5)
axis(1, at = seq(min(pyear), max(pyear), 1), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
axis(2, at = seq(0, 140, 10), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
matlines(pyear, predict(fit, newdata=list(year=pyear), interval="confidence"), lwd=1.25)

Summary of logistic regression with average values
pyear <- seq(1990, 2030, 1)
plot(x=pyear, y=c(), xlim = c(min(pyear), max(pyear)), ylim=c(0,140),
ylab = "IT.CEL.SETS.P2", xlab = "year", xaxt='n',yaxt='n')
axis(1, at = seq(min(pyear),max(pyear), 1), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
axis(2, at = seq(0, 140, 10), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
colors <- c("blue","red","orange","green")
names(colors) <- income_grp
for (grp in income_grp) {
gdat <- get_data(dat, grp, is.mean = T)
points(x=gdat$year, y=gdat$IT.CEL.SETS.P2, pch=16, col=colors[grp], xaxt='n', yaxt='n', cex=0.75)
matlines(pyear, predict(smdls[[grp]], newdata=list(year=pyear), interval="confidence"), lwd=1)
}
legend("bottomright", legend=c("high income","low income","lower middle income","upper middle income"),
col=colors, lty=0, cex = 0.75, bg = "transparent", pch=16, box.lty=0)

pyear <- seq(1990, 2030, 1)
plot(x=pyear, y=c(), xlim = c(min(pyear), max(pyear)), ylim=c(0,140),
ylab = "IT.CEL.SETS.P2", xlab = "year", xaxt='n',yaxt='n')
axis(1, at = seq(min(pyear),max(pyear), 1), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
axis(2, at = seq(0, 140, 10), tck = 1, lty = 4, col = "lightgray", lwd = 0.75)
colors <- c("blue","red","orange","green")
names(colors) <- income_grp
for (grp in income_grp) {
gdat <- get_data(dat, grp, is.mean = F)
points(x=gdat$year, y=gdat$IT.CEL.SETS.P2, pch=16, col=colors[grp], xaxt='n', yaxt='n', cex=0.25)
matlines(pyear, col = colors[grp], predict(smdls[[grp]], newdata=list(year=pyear), interval="confidence"), lwd=1)
}
legend("bottomright", legend=c("high income","low income","lower middle income","upper middle income"),
col=colors, lty=0, cex = 0.75, bg = "transparent", pch=16, box.lty=0)
